//显示一级下拉框
function show_area_province(depth,area_json){
	var html = '<select name="search_province" id="search_area_0" op_type="search_province" class="querySelect">';;
	html += ('<option value="0">请选择...</option>');
	
	if(area_json){
		for(var i in area_json){
			if(depth == 1){
				html += ('<option value="'+area_json[i].id+'">'+area_json[i].name+'</option>');
			}
		}
	}
	html += '</select>';
	$("#searcharea").html(html);
}
//显示二级下拉框
function show_area_city(chooseid,area_json){
	if(area_json && chooseid > 0){
		if(area_json){
			var html = '<select name="search_city" id="search_area_2" op_type="search_city" onchange="op_area(this.value);" class="querySelect">';
			html += ('<option value="0">请选择...</option>');
			for(var i in area_json){
				html += ('<option value="'+area_json[i].id+'">'+area_json[i].name+'</option>');
			}
			html += '</select>';
			$("#searcharea").append(html);
		}
	}
}
//显示三级下拉框
function show_area(chooseid,area_json){
	if(area_json && chooseid > 0){
		if(area_json){
			var html = '<select name="search_area" id="search_area_3" op_type="search_area" class="querySelect">';;
			html += ('<option value="0">请选择...</option>');
			for(var i in area_json){
				html += ('<option value="'+area_json[i].id+'">'+area_json[i].name+'</option>');
			}
			html += '</select>';
			$("#searcharea").append(html);
		}
	}
}
function get_area(id,area){
	var dataParass={"parentid":id};
	$.ajax({
		cache: true,
		type: "POST",
		url:"http://onethink.tp.cn/index.php?s=/admin/leaveword/ajax_area.html",
		data:dataParass,
		async: false,
		dataType:'json',
		error: function(request) {
			//alert("Connection error");
			return 0;
		},
		success: function(data) {
			if(area == 'province'){
				show_area_city(id,data);
			}
			if(area == 'city'){
				show_area(id,data);
			}
		}
	});
}
//初始化区域select
function init_area(chooseid_json,area_json){
	show_area_province(1,area_json);
	//触发省级
	$("[op_type='search_province']").on('change',function(){
        $(this).nextAll("[op_type='search_city']").remove();
		$(this).nextAll("[op_type='search_area']").remove();
        var chooseid = $(this).val();
		if(chooseid > 0){
			get_area(chooseid,'province');
		}
    });
}
function op_area(chooseid){
	$("#search_area_3").remove();
	if(chooseid > 0){
		get_area(chooseid,'city');
	}
}